#ifndef MUTEX_HH
#define MUTEX_HH

/*!
 * \file mutex.hh
 * \brief contains a generic mutex implementation to inherit from
 * \author Xavier SCHMERBER
 * \version 1
 */

#include <pthread.h>
#include <stdexcept>

using namespace std;

/*!
 * \brief The Mutex class: Generic mutex implementation to inherit from
 *  - A very simple way to protect an object that needs to be accessed by multiple threads
 *  - Objects should inherit from this class and use lock / unlock functions for concurrential accesses
 */
class Mutex
{
private: //vars
    pthread_mutex_t _lock;          // mutex variable

public: // public methods
    /*!
     * \brief Mutex: Standard constructor
     */
    Mutex();                        // Standard constructor
    /*!
     * \brief ~Mutex: Standard destructor
     */
    ~Mutex();                       // Standard destructor

protected: // heritage methods
    /*!
     * \brief lock: lock the mutex (and wait if locked)
     * \return true / false
     */
    bool lock();                    // lock the mutex (and wait if locked)
    /*!
     * \brief unlock: unlock the mutex
     * \return true / false
     */
    bool unlock();                  // unlock the mutex

private: // internal methods
};

#endif // MUTEX_HH
